package com.huaxin.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huaxin.device.dto.ResponseResult;
import com.huaxin.device.dto.request.SwitchCabinetTypeCreateReqDTO;
import com.huaxin.device.dto.request.SwitchCabinetTypePageListReqDTO;
import com.huaxin.device.dto.request.SwitchCabinetTypeUpdateReqDTO;
import com.huaxin.device.models.SwitchCabinetType;
import com.huaxin.device.service.SwitchCabinetTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "变电箱类型")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/device/switchCabinetType")
public class SwitchCabinetTypeController {

    private final SwitchCabinetTypeService service;

    @Operation(summary = "创建变电箱类型", description = "创建变电箱类型")
    @PostMapping("/create")
    public ResponseResult<SwitchCabinetType> create(@RequestBody @Valid SwitchCabinetTypeCreateReqDTO in) {
        return service.create(in);
    }

    @Operation(summary = "获取变电箱类型", description = "根据ID获取变电箱类型")
    @GetMapping("/get")
    public ResponseResult<SwitchCabinetType> get(
            @Parameter(description = "类型ID", example = "sc123e456-789a-bcde-f012-3456789abcde")
            @RequestParam("id") String id) {
        return ResponseResult.ok(service.getByTypeId(id));
    }

    @Operation(summary = "更新变电箱类型", description = "更新变电箱类型信息")
    @PostMapping("/update")
    public ResponseResult<String> update(@RequestBody @Valid SwitchCabinetTypeUpdateReqDTO in) {
        return service.update(in);
    }

    @Operation(summary = "删除变电箱类型", description = "删除变电箱类型")
    @DeleteMapping("/{id}/delete")
    public ResponseResult<String> delete(
            @Parameter(description = "类型ID", example = "sc123e456-789a-bcde-f012-3456789abcde")
            @PathVariable String id) {
        return service.delete(id);
    }

    @Operation(summary = "分页查询变电箱类型", description = "分页查询变电箱类型")
    @PostMapping("/page")
    public ResponseResult<IPage<SwitchCabinetType>> pageQuery(@RequestBody @Valid SwitchCabinetTypePageListReqDTO in) {
        return service.pageQuery(in);
    }
}